//
//	Simple test application to demonstrate
//	the card bitmap library
//
//	Written by J Brown 30/10/2001.
//	Freeware.
//
#include <windows.h>
#include <tchar.h>
#include "CardBitmap.h"
#include "resource.h"

int cardwidth, cardheight;

BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	RECT rect;
	int width, height;

	switch(msg)
	{
	case WM_INITDIALOG:
		SetTimer(hwnd, 1234, 50, 0);
		return TRUE;

	case WM_CTLCOLORDLG:
		return (BOOL)GetSysColorBrush(COLOR_APPWORKSPACE);

	case WM_CLOSE:
		EndDialog(hwnd, 0);
		return TRUE;

	case WM_TIMER:

		GetClientRect(hwnd, &rect);
		width = rect.right;
		height = rect.bottom;

		if(width != 0 && height != 0)
		{
			HDC hdc = GetDC(hwnd);

			CardBlt(hdc, rand() % width, rand() % height, rand() % MAX_CARD_BITMAPS);
			
			ReleaseDC(hwnd, hdc);
		}

		return TRUE;

	case WM_COMMAND:

		switch(LOWORD(wParam))
		{
		case IDCANCEL: case IDOK:
			EndDialog(hwnd, 0);
			return TRUE;
		}

		return FALSE;
	}

	return FALSE;
}

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nShowCmd)
{
	LoadCardBitmaps(&cardwidth, &cardheight);

	DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), 0, DlgProc);
	
	FreeCardBitmaps();

	return 0;
}